package com.ryskoo.catering.productmain.domain;

import com.ryskoo.catering.productattr.domain.ProductAttrPO;
import com.ryskoo.catering.productimage.domain.ProductImagePO;
import com.ryskoo.catering.productspec.domain.ProductSpecPO;
import com.ryskoo.framework.core.bean.BasicPO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.*;
import java.util.List;

@Entity
@Table(name = "cater_product_main")
@Document(indexName = "product", type = "main")
public class ProductMainPO extends BasicPO {

    /** 主键 */
    @org.springframework.data.annotation.Id
    @Id
    @Column(name = "uuid", columnDefinition = "char(32)", length = 32, nullable = false)
    private String uuid;

    /**
     * 菜品所属分类id
     */
    @Column(name = "category_uuid", columnDefinition = "char", length = 32)
    private String categoryUuid;

    /**
     * 菜品所属分类名称
     */
    @Field(type = FieldType.String, analyzer = "ik_max_word", searchAnalyzer = "ik_smart", store = true)
    @Transient
    private String categoryName;

    /**
     * 菜品所属推荐分类uuid
     */
    @Column(name = "recommend_category_uuid", columnDefinition = "char", length = 32)
    private String recommendCategoryUuid;

    /**
     * 商品名称
     */
    @Field(type = FieldType.String, analyzer = "ik_max_word", searchAnalyzer = "ik_smart", store = true)
    @Column(name = "name", columnDefinition = "varchar", length = 30)
    private String name;

    /**
     * 商品价格
     */
    @Column(name = "price", columnDefinition = "decimal", length = 11, precision = 2)
    private double price;

    /**
     * 促销类型 0-不参与；1-折扣；2-优惠
     */
    @Column(name = "promotion_type", columnDefinition = "tinyint", length = 2)
    private int promotionType;

    /**
     * 折扣比率
     *
     */
    @Column(name = "promotion_rate",columnDefinition = "decimal",length = 11,precision = 2)
    private double promotionRate;

    /**
     * 菜品促销价格
     */
    @Column(name = "promotion_price", columnDefinition = "decimal", length = 11, precision = 2)
    private double promotionPrice;

    /**
     * 餐盒费用
     */
    @Column(name = "lunchbox_price", columnDefinition = "decimal", length = 11, precision = 2)
    private double lunchboxPrice;

    /**
     * 商品大图
     */
    @Column(name = "bigimg", columnDefinition = "varchar", length = 100)
    private String bigimg;

    /**
     * 商品小图
     */
    @Column(name = "smallimg", columnDefinition = "varchar", length = 100)
    private String smallimg;

    /**
     * 商品备注
     */
    @Column(name = "note", columnDefinition = "varchar", length = 50)
    private String note;

    /**
     * 商品标签
     */
    @Column(name = "tag", columnDefinition = "char(32)", length = 32)
    private String tag;

    /**
     * 上下架状态 1-上架；0-下架
     */
    @Column(name = "state")
    private boolean state = true;

    /**
     * 所属商户UUID
     */
    @Column(name = "vendor_uuid", columnDefinition = "char", length = 32)
    private String vendorUuid;

    /**
     * 所属商户名称
     */
    @Field(type = FieldType.String, analyzer = "ik_max_word", searchAnalyzer = "ik_smart", store = true)
    @Column(name = "vendor_name", columnDefinition = "varchar", length = 20)
    private String vendorName;

    /**
     * 是否是规格商品 1-是；0-否
     */
    @Column(name = "is_spec")
    private boolean isSpec = false;

    /**
     * 是否售罄，1-是，0-否
     */
    @Column(name = "is_sell_out")
    private boolean isSellOut = false;

    /**
     * 商品赠送积分
     */
    @Column(name = "integral",columnDefinition = "int")
    private int integral;

    /**
     * 月销数量
     */
    @Transient
    private int monthSell = 0;
    @Transient
    private List<ProductSpecPO> productSpecList;

    @Transient
    private List<ProductAttrPO> productAttrList;
    /**
     * 规格属性集合，用于菜品编辑时展示
     */
    @Transient
    private List<ProductAttrPO> productSpecAttrList;
    /**
     * 非规格属性集合，用于菜品编辑时展示
     */
    @Transient
    private List<ProductAttrPO> productNoSpecAttrList;

    /**
     * 属性值uuid集合字符串
     */
    @Transient
    private String attrValueUuids;

    /**
     * 属性集合json字符串，放到APP商品编辑页面的隐藏域中
     */
    @Transient
    private String attrsJson;
    @Transient
    private String productNoSpecAttrNames;
    @Transient
    private List<ProductImagePO> productImageList;

    @Override
    public String getUuid() {
        return uuid;
    }

    @Override
    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public int getMonthSell() {
        return monthSell;
    }

    public void setMonthSell(int monthSell) {
        this.monthSell = monthSell;
    }

    public List<ProductImagePO> getProductImageList() {
        return productImageList;
    }

    public void setProductImageList(List<ProductImagePO> productImageList) {
        this.productImageList = productImageList;
    }

    public List<ProductSpecPO> getProductSpecList() {
        return productSpecList;
    }

    public void setProductSpecList(List<ProductSpecPO> productSpecList) {
        this.productSpecList = productSpecList;
    }

    public List<ProductAttrPO> getProductAttrList() {
        return productAttrList;
    }

    public void setProductAttrList(List<ProductAttrPO> productAttrList) {
        this.productAttrList = productAttrList;
    }

    public String getCategoryUuid() {
        return categoryUuid;
    }

    public void setCategoryUuid(String categoryUuid) {
        this.categoryUuid = categoryUuid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getBigimg() {
        return bigimg;
    }

    public void setBigimg(String bigimg) {
        this.bigimg = bigimg;
    }

    public String getSmallimg() {
        return smallimg;
    }

    public void setSmallimg(String smallimg) {
        this.smallimg = smallimg;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public boolean isState() {
        return state;
    }

    public void setState(boolean state) {
        this.state = state;
    }

    public String getVendorUuid() {
        return vendorUuid;
    }

    public void setVendorUuid(String vendorUuid) {
        this.vendorUuid = vendorUuid;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public String getVendorName() {
        return vendorName;
    }

    public void setVendorName(String vendorName) {
        this.vendorName = vendorName;
    }

    public boolean isSpec() {
        return isSpec;
    }

    public void setSpec(boolean spec) {
        isSpec = spec;
    }

    public boolean isSellOut() {
        return isSellOut;
    }

    public void setSellOut(boolean sellOut) {
        isSellOut = sellOut;
    }

    public String getRecommendCategoryUuid() {
        return recommendCategoryUuid;
    }

    public void setRecommendCategoryUuid(String recommendCategoryUuid) {
        this.recommendCategoryUuid = recommendCategoryUuid;
    }

    public double getPromotionPrice() {
        return promotionPrice;
    }

    public void setPromotionPrice(double promotionPrice) {
        this.promotionPrice = promotionPrice;
    }

    public double getLunchboxPrice() {
        return lunchboxPrice;
    }

    public void setLunchboxPrice(double lunchboxPrice) {
        this.lunchboxPrice = lunchboxPrice;
    }

    public int getPromotionType() {
        return promotionType;
    }

    public void setPromotionType(int promotionType) {
        this.promotionType = promotionType;
    }

    public int getIntegral() {
        return integral;
    }

    public void setIntegral(int integral) {
        this.integral = integral;
    }

    public String getAttrsJson() {
        return attrsJson;
    }

    public void setAttrsJson(String attrsJson) {
        this.attrsJson = attrsJson;
    }

    public List<ProductAttrPO> getProductSpecAttrList() {
        return productSpecAttrList;
    }

    public void setProductSpecAttrList(List<ProductAttrPO> productSpecAttrList) {
        this.productSpecAttrList = productSpecAttrList;
    }

    public List<ProductAttrPO> getProductNoSpecAttrList() {
        return productNoSpecAttrList;
    }

    public void setProductNoSpecAttrList(List<ProductAttrPO> productNoSpecAttrList) {
        this.productNoSpecAttrList = productNoSpecAttrList;
    }

    public double getPromotionRate() {
        return promotionRate;
    }

    public void setPromotionRate(double promotionRate) {
        this.promotionRate = promotionRate;
    }

    public String getProductNoSpecAttrNames() {
        productNoSpecAttrNames = "";
        if(null!=productNoSpecAttrList&&productNoSpecAttrList.size()>0){
            for (ProductAttrPO attrPO:productNoSpecAttrList) {
                if(attrPO.isStatus()){
                    productNoSpecAttrNames += attrPO.getName()+",";
                }
            }
        }
        if(!StringUtils.isEmpty(productNoSpecAttrNames)){
            productNoSpecAttrNames = productNoSpecAttrNames.substring(0,productNoSpecAttrNames.length()-1);
        }
        return productNoSpecAttrNames;
    }

    public void setProductNoSpecAttrNames(String productNoSpecAttrNames) {
        this.productNoSpecAttrNames = productNoSpecAttrNames;
    }

    public String getAttrValueUuids() {
        return attrValueUuids;
    }

    public void setAttrValueUuids(String attrValueUuids) {
        this.attrValueUuids = attrValueUuids;
    }
}
